//Page Object
import moment from "moment";
import {request} from "../../request/index.js";
Page({
  data: {
    swiperList:[],
    goodsList:[],
    askList:[],
    floorList:[],
    freeList:[],
    active:0
   
  },
  //options(Object)
  onLoad: function(options) {
   
  
    
    this.getGoodsList();
    this.getSwiperList();
   
  },
  onShow:function(){
    this.onLoad()
  },
  onClick(event) {
    // wx.showToast({
    //   title: `点击标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
   
    if(event.detail.title == '求购专区'){
      this.getAskList()
    }
    else if(event.detail.title == '免费专区'){
      this.getFreeList()
    }
    
  },

 
  

  toGoodsInfo(e){
    if (!e.currentTarget.dataset.id) {
      wx.showToast({
        title: '商品id不能为空',
        icon: 'none',
        duration: 2000
      })
      return
    }
    wx.navigateTo({
      url: '/pages/goodsInfo/goodsInfo?id=' + e.currentTarget.dataset.id,
    })
  },


  toAskInfo(e){
    if (!e.currentTarget.dataset.id) {
      wx.showToast({
        title: '商品id不能为空',
        icon: 'none',
        duration: 2000
      })
      return
    }
    wx.navigateTo({
      url: '/pages/askInfo/askInfo?id=' + e.currentTarget.dataset.id,
    })
  },

  //获取轮播图
  async getSwiperList(){
    // wx.request({  
    //   url: 'http://127.0.0.1:6060/api/getImageList',  
    //   method:'get',  
    //   success: (res)=> {  
    //     this.setData({
    //       swiperList: res.data.message
    //     })
    //   }  
    // })
    const res = await request({
      url:'http://127.0.0.1:6060/api/getImageList',
      method:'get'
    })
    console.log(res)
    this.setData({
      swiperList:res.data.message
    })
  },


  //获取商品信息
  async getGoodsList(){
    // wx.request({  
    //   url: 'http://127.0.0.1:6060/api/getGoodsList',  
    //   method:'get',  
    //   success: (res)=> {  
      
    //     this.setData({
    //       goodsList: res.data.data
    //     })
      
    //   }  
    // })

    const res = await request({
      url:'http://127.0.0.1:6060/api/getGoodsList',
      method:'post',
    
    })
    console.log(res)
    this.setData({
      goodsList:res.data.data
    })
  },


  //获取免费商品列表
  getFreeList(){
    wx.request({  
      url: 'http://127.0.0.1:6060/api/getFreeList',  
      method:'get',  
      success: (res)=> {  
      
        this.setData({
          freeList: res.data.message
        })
      
      }  
    })
  },

  //获取求购信息
  getAskList(){
    wx.request({  
      url: 'http://127.0.0.1:6060/api/getAskList',  
      method:'get',  
      success: (res)=> {  
      
        this.setData({
          askList: res.data.message
        })
      
      }  
    })
  },
  
  
 
});
  